<template>
    <div class="div">
  <div class="div1" >
     <div @click="toNewsPage(item)" class="div2" v-for="item in newsList" :key="item.index">
        
        <img class="item_img" :src="'http://localhost:3000'+item.cover" alt="">
        <span style="display: flex;flex-direction: column;">
         
             <span style="margin-bottom: 10px; display: flex; flex-direction: column;">
                <el-text class="font_title" tag="b" line-clamp="2">{{ item.title }}</el-text>
                <el-text class="font_time">{{ Store.editTime(item.editTime)  }}</el-text>
            </span>
        </span>
      
    </div>
  </div>
</div>
</template>

<script setup>
import { onMounted,ref } from "vue"
import {getnewnewslist} from '@/request/home/userapi.js'
import {useStore} from "@/stores/counter.js";

import { useRouter } from "vue-router";
const Store =useStore()
const Router = useRouter()
const newsList = ref()
const toNewsPage = (value) => {
    Router.push({
        name:'newpage',
        query:{
            new:JSON.stringify(value)
        }
    })
}
  onMounted(async ()=>{
    const result = await getnewnewslist(4)
   newsList.value = result.data.result

  })
</script>

<style scoped>
.div1{

    margin-top:20px ;
    display: flex;
    justify-content: space-around;
    
}
.div2{
    background: white;
    width: 20%;
    height: 400px;
    margin:10px 0.1rem ;
    box-shadow: inset 8px 8px 8px rgba(0, 0, 0, 0.3),
    inset -8px -8px 8px rgba(255, 255, 255, 0.7),
    -10px -10px 10px rgba(0,0,0,0.4)
    ;
    border-radius:8px;

    display: flex;
    flex-direction:column ;
    justify-content: space-between;
    transition: all 0.3s;
}
.font_title{
    width: 90%; font-size: 0.2rem; color: black;
}
.font_time{
    width: 90%;  font-size: 0.1rem; font-weight: 600;
}
.item_img{
    border-radius:8px 8px 0 0  ;
    width: 100%;
    max-height: 70%;
}
.div2:hover{
    box-shadow:  0 0 15px rgba(0,0,0,0.5);
    transform: translateY(-8px) scale(1.02);
}
@media (max-width: 1000px) {
    .div2{
        width: 40%;
        height: 300px;
    }
    .div1{
        flex-wrap: wrap;
    }
    .font_time{
        font-size: 0.15rem;
    }
    .font_title{
        font-size: 0.3rem;
    }
    
}
@media (max-width: 450px){
    .div2{
        width: 40%;
        height: 200px;
    }
    
}
</style>